/**
 * losenote.com Inc.
 * Copyright (c) 2013-2013 All Rights Reserved.
 */
package com.losenote.model.ct;

import com.losenote.enums.MessageTypeEnum;
import com.losenote.model.Message;
import com.losenote.model.OperateContext;
import com.losenote.orm.MessageDO;

/**
 * 
 * @author danjingyu
 * @version $Id: MessageConvertor.java, v 0.1 2013-12-1 下午4:48:39 danjingyu Exp $
 */
public class MessageConvertor {

    /**
     * model转换
     * 
     * @param message
     * @param context
     * @return
     */
    public static MessageDO fromMode(Message message, OperateContext context) {
        MessageDO messageDO = new MessageDO();
        messageDO.setCreator(message.getCreator());
        messageDO.setGmtCreate(message.getGmtCreate());
        messageDO.setFatherId(message.getLastId());
        messageDO.setMessage(message.getContent());
        messageDO.setRelId(message.getRelId());
        messageDO.setRelType(message.getRelType().getValue());
        return messageDO;
    }

    /**
     * model转换
     * 
     * @param message
     * @param context
     * @return
     */
    public static Message fromDO(MessageDO messageDO) {
        Message message = new Message();
        message.setCreator(messageDO.getCreator());
        message.setGmtCreate(messageDO.getGmtCreate());
        message.setContent(messageDO.getMessage());
        message.setRelType(MessageTypeEnum.getByValue(messageDO.getRelType()));
        message.setRelId(messageDO.getRelId());
        message.setLastId(messageDO.getFatherId());
        return message;
    }
}
